import updateChildren from "./updateChildren";

export default function patchVnode(oldVode,newVode){
    if(newVode === oldVode){
        return
    }
    if(newVode.text != undefined &&(newVode.children===undefined || newVode.children.length=== 0)){
        //新vnode有text属性
        if(newVode.text!== oldVode.text){
            oldVode.elm.innerText = newVode.text
        }
    }else{
        if(oldVode.children !== undefined && oldVode.children.length>0){
            updateChildren(oldVode.elm,oldVode.children,newVode.children)
        }else{
            //老的没有children,新的有children
            //清空老的内容
            oldVode.elm.innerText = '';
            //遍历新的vnode的子节点，创建Dom,上树
            for(let i=0 ; i<newVode.children.length;i++){
              let dom = createElement(newVode.children[i]);
              oldVode.elm.appendChild(dom);
            }
        }
    }
}